package cn.like.backEnd.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import com.github.xiaoymin.knife4j.spring.extension.OpenApiExtensionResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * @author like 980650920@qq.com
 * @date 2021/7/7 21:54
 */
@Configuration
@EnableSwagger2WebMvc
@EnableKnife4j
public class Knife4jConfiguration {
	
	private final OpenApiExtensionResolver openApiExtensionResolver;
	
	@Bean(value = "helloApi")
	public Docket helloApi() {
		return new Docket(DocumentationType.SWAGGER_2)
		  .apiInfo(apiInfo())
		  //分组名称
		  .select()
		  //这里指定Controller扫描包路径
		  .apis(RequestHandlerSelectors.basePackage("cn.like.backEnd.controller"))
		  .paths(PathSelectors.any())
		  .build()
		  .extensions(openApiExtensionResolver.buildExtensions("Admin 模块"));
	}
	
	@Autowired
	public Knife4jConfiguration(OpenApiExtensionResolver openApiExtensionResolver) {
		this.openApiExtensionResolver = openApiExtensionResolver;
	}
	
	public ApiInfo apiInfo() {
		return new ApiInfoBuilder()
		  .title("Like api doc")
		  .description("like back end api doc")
		  .termsOfServiceUrl("https://github.com/likedeke")
		  .contact(new Contact("like", "https://www.yuque.com/ekoc", "likelovec@gmail.com"))
		  .version("1.0")
		  .build();
	}
}
